<?php

// $Id$

require_once(TANGRA_MAIN_DIR.'interfaces/i_db_storable.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/tcms_registry_keys.class.php');
require_once($WSC->get_site_inc_dir().'modules/registry_db/registry_key_db.class.php');


class TCMS_Settings_Sitemap_DBC extends Tangra_Class implements I_DB_Storable {
	private $id;
	private $mode;
	private $weight;
	private $change_freq;

	//fake
	public function set_id($id) {
	}


	//fake
	public function get_id() {
		return 1;
	}


	public function save(DB_Connection $dbc) {
		$this->mode->save($dbc);
		$this->weight->save($dbc);
		$this->change_freq->save($dbc);

		return 1;
	}


	public function load_by_id(DB_Connection $dbc, $id) {
		tangra_if_not_int_throw_e($id);

		$mode_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_SITEMAP_MODE);
		if ($mode_id) {
			$mode = new Registry_Key_DB();
			$mode->load_by_id($dbc, $mode_id);
			$this->mode = $mode;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_SITEMAP_MODE);
		}

		$weight_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_SITEMAP_DEFAULT_WEIGHT);
		if ($weight_id) {
			$weight = new Registry_Key_DB();
			$weight->load_by_id($dbc, $weight_id);
			$this->weight = $weight;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_SITEMAP_DEFAULT_WEIGHT);
		}

		$change_freq_id = Registry_Key_DB::key_exists($dbc, TCMS_Registry_Keys::KEY_TCMS_SITEMAP_DEFAULT_CHANGE_FREQ);
		if ($change_freq_id) {
			$change_freq = new Registry_Key_DB();
			$change_freq->load_by_id($dbc, $change_freq_id);
			$this->change_freq = $change_freq;
		} else {
			throw new Tangra_Module_Exception('Registry key missing: '.TCMS_Registry_Keys::KEY_TCMS_SITEMAP_DEFAULT_CHANGE_FREQ);
		}


		return 1;
	}


	public function set_mode($value) {
		$this->mode->set_value($value ? 1 : 0);
	}


	public function get_mode() {
		return $this->mode->get_value();
	}


	public function set_weight($value) {
		$this->weight->set_value($value);
	}


	public function get_weight() {
		return $this->weight->get_value();
	}


	public function set_change_freq($value) {
		$this->change_freq->set_value($value);
	}


	public function get_change_freq() {
		return $this->change_freq->get_value();
	}
}